package china.lzy.controller;

import china.lzy.api.UserControllerApi;

import china.lzy.entity.ResResult;
import china.lzy.entity.dto.PageDto;
import china.lzy.entity.pojo.User;
import china.lzy.service.UserService;
import china.lzy.utils.anno.Authorization;
import china.lzy.utils.anno.NoAuthorization;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author ：lzy
 * @ Date       ：Created in 16:35 2021/8/9
 * @ Description：用户类
 */

@RestController
@RequestMapping("/user")
public class UserController  implements UserControllerApi {

    @Autowired
    UserService userService;

    @NoAuthorization
    @PostMapping("/save")
    @Override
    public ResResult save(@RequestBody User user) {
        System.out.println(user);
        return userService.saveUser(user);
    }

    @NoAuthorization
    @PostMapping("/login")
    @Override
    public ResResult login(@RequestBody User user) {
        return userService.login(user);
    }


    @Authorization({"admin", "consumer"})
    @PostMapping("/update")
    @Override
    public ResResult update(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @Authorization({"admin"})
    @PostMapping("/delete")
    @Override
    public ResResult delete(@RequestBody User user) {
        return userService.delete(user);
    }


    @Authorization({"admin"})
    @PostMapping("/select")
    @Override
    public ResResult findByPage(@RequestBody PageDto page) {
        return userService.findByPage(page);
    }
}
